<div class="blog_change">
	<div class="title">
		<span class="title_title">标题:</span>
    	<input id="title" class="title_content text" type="text" value="<?php if(isset($articleID)){echo $article['article_title'];} ?>">
    </div>
    <div class="class">
    	<span class="class_title">分类:</span>
    	<select id="main_class" class="class_content" onchange="showSubClass();">
    		<option value="-1">选择父类</option>
    		<?php foreach ($class as $key=>$value){ if(!$value['subClass']) continue;?>
    			<option value="<?=$key?>"><?=$value['name']?></option>
    		<?php } ?>
    	</select>
    	<select id="sub_class" class="class_content">
    		<option value="-1">选择子类</option>
    	</select>
	</div>
	<div id="panel"></div>
	<div id="article" class="article edit">
	    <?php if(isset($articleID)){echo $article['article_content'];}?>
	</div>
	<div class="func">
		<input type="button" id="public_btn" class="btn btn_input" value="发表文章" />
		<input type="button" id="draft_btn" class="btn btn_input" value="保存草稿" />
		<?php if(isset($articleID)){?>
		<input type="button" id="cancel_btn" class="btn btn_input" value="取消" />
		<?php }?>
	</div>
</div>
<script src="<?=STATIC_PATH?>Js/nicedit/nicEdit.js" type="text/javascript"></script>
<script type="text/javascript">
    myEditor = new nicEditor({fullPanel : true});
    myEditor.setPanel('panel');
    myEditor.addInstance('article');
    myEditor = myEditor.instanceById('article')
	function showSubClass()
	{
		mainClassID = $("#main_class").val();
		allClassData = <?=json_encode($class)?>;
		$("#sub_class")[0].options.length=1;
		for(var i in allClassData[mainClassID]['subClass'])
		{
			subClass = allClassData[mainClassID]['subClass'][i];
			$("#sub_class")[0].options.add(new Option(subClass['class_name'],subClass['class_id']));
		}
	}
	<?php if(isset($articleID)){?>
    function initClass()
    {
    	$("#main_class").val(<?=$article['article_main_class_id']?>);
    	showSubClass();
    	$("#sub_class").val(<?=$article['article_sub_class_id']?>);
    }
    initClass();
	$("#cancel_btn").click(function(){
		if(!confirm("确定取消？")) return;
    	location.href = "http://<?=HOST?>/blog/detail/id/<?=$articleID?>";
    });
    <?php }else{?>
    myEditor.setContent("");
    <?php }?>
    $("#public_btn").click(function(){
    	var title      = $.trim($("#title").val());
    	var main_class = $("#main_class").val();
    	var sub_class  = $("#sub_class").val();
        $.ajax({
    		  url: "http://<?=HOST?>/blog/editAjax",
    		  cache: false,
    		  timeout:10000,
    		  type: "POST",
    		  data: {
    			title:title,
    			main_class:main_class,
    			sub_class:sub_class,
    			<?php if(isset($articleID) && $articleID){?>
    			article_id:<?=$articleID?>,
    			<?php }?>
    			article:myEditor.getContent()
    		  },
    		  dataType: "json",
    		  beforeSend: function() {
				  disableHTML(true, '请稍等，保存中……', true);
			  },
    		  success: function(data) {
        		  if(data.errCode != 0)
        		  {
        			  disableHTML(true, data.errMsg, false);
        			  setTimeout(disableHTML,2000);
            		  if(data.errCode == -1)
            		  {
            			  $("#title").focus();
            		  }
        		  }
        		  else
        		  {
        			  disableHTML(true, '保存成功，跳转中……', true);
        			  <?php if(isset($articleID) && $articleID){?>
        			      setTimeout("location.href = 'http://<?=HOST?>/blog/detail/id/<?=$articleID?>'",2000);
        			  <?php }else{?>
        			      setTimeout("location.href = 'http://<?=HOST?>/blog/detail/id/"+data.id+"'",2000);
        			  <?php }?>
        		  }
    		  },
        	  error:function(){
          		  disableHTML(true, "请求出错，请重试", false);
          		  setTimeout(disableHTML,2000);
          	   }
    		});
	});
</script>